package com.stox.charting.ui.swing.model.uiUnit;

import java.awt.Graphics;
import java.awt.Rectangle;

import com.stox.charting.ui.swing.model.ChartModel;
import com.stox.charting.ui.swing.model.indicator.BarChartModel;

public class BarUiUnit extends AbstractUiUnit<Double> {
	
	public BarUiUnit(BarChartModel model, int index) {
		super(model, index);
	}
	
	@Override
	public void processUi(double width, double factor) {
		ChartModel<Double> model = getModel();
		setWidth(width);
		setX((int)(width*(model.getViewport().getStartIndex() - getIndex() -1)));
		Rectangle r = model.getChart().getVisibleRect();
		setY((int)(r.getHeight() - (getValue()-model.getViewport().getMinimumValueVisible())*factor));
		setHeight(r.getY()+r.getHeight() - getY());
	}
	
	@Override
	public void paint(Graphics g) {
		g.setColor(getColor());
		g.fillRect(getX(), getY(), (int)Math.ceil(getWidth()), (int)Math.ceil(getHeight()));
	}
}
